//
//  WYMainViewController.m
//  WYDevDemo
//
//  Created by longtu on 15/5/20.
//  Copyright (c) 2015年 longtu. All rights reserved.
//

#import "WYMainViewController.h"

#import<SystemConfiguration/SCNetworkReachability.h>
#import <arpa/inet.h>

#import "WYDevHelper.h"
#import "WYDeviceHelper.h"

@interface WYMainViewController (){
    UILabel *lab;
}

@end

@implementation WYMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [WYDeviceHelper locationBlock:^(float latitude, float longitude) {
        NSLog(@"lat=%f--lon=%f", latitude, longitude);
    } errorBlock:^(NSError *error) {
        NSLog(@"%@", error);
    }];
    
    
    lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 320, 40)];
    lab.textAlignment = NSTextAlignmentCenter;
    NSString *str = @"测试";
    switch ([WYHttpHelper connectedToNetwork]) {
        case NotReachable:
            str = @"无网络";
            break;
        case ReachableViaWiFi:
            str = @"WiFi 网络";
            break;
        case ReachableViaWWAN:
            str = @"WWAN 网络";
            break;
        case ReachableVia3G:
            str = @"3G 网络";
            break;
        case ReachableVia2G:
            str = @"2G 网络";
            break;
        default:
            break;
    }
    lab.text = str;
    [self.view addSubview:lab];
    
    
}

#pragma mark - 摇动方法
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    //检测到摇动
    NSLog(@"检测到摇动");
    static int i = 1;
    NSString *str = @"测试";
    switch ([WYHttpHelper connectedToNetwork]) {
        case NotReachable:
            str = [NSString stringWithFormat:@"无网络-%d",i++];
            break;
        case ReachableViaWiFi:
            str = [NSString stringWithFormat:@"WiFi 网络-%d",i++];
            break;
        case ReachableViaWWAN:
            str = [NSString stringWithFormat:@"WWAN 网络-%d",i++];
            break;
        case ReachableVia3G:
            str = [NSString stringWithFormat:@"3G 网络-%d",i++];
            break;
        case ReachableVia2G:
            str = [NSString stringWithFormat:@"2G 网络-%d",i++];
            break;
            
        default:
            break;
    }
    lab.text = str;
}

- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    //摇动取消
    NSLog(@"摇动取消");
}

- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    //摇动结束
    if (event.subtype == UIEventSubtypeMotionShake) {
        //something happens
        NSLog(@"摇动取消");
    }
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
